package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "项目等级")
public class NursingLevelController {
    @Autowired
    private NursingLevelService nursingLevelService;

    //查询项目等级
    @GetMapping("/listAll")
    @ApiOperation(value = "查询项目等级")
    public ResponseResult<List<NursingLevelDto>> selectNursingLevel() {
        List<NursingLevelDto> list = nursingLevelService.select();
        return ResponseResult.success(list);
    }

    //新增护理等级
    @PostMapping("/insert")
    @ApiOperation(value = "新增项目等级")
    public ResponseResult insert(@ApiParam(value = "护理等级数据", required = true)
                                 @RequestBody NursingLevelDto nursingLevelDto) {
        nursingLevelService.insert(nursingLevelDto);
        return ResponseResult.success();
    }
    //分页条件查询
    @ApiOperation(value = "分页查询项目等级")
    @GetMapping("/listByPage")
    public ResponseResult<PageResponse<NursingLevelVo>> listByPage(@ApiParam(value = "等级名称")
                                     @RequestParam(value = "name", required = false) String name,
                                                                   @ApiParam(value = "状态，0：禁用，1：启用")
                                     @RequestParam(value = "status",required = false) Integer status,
                                                                   @ApiParam (value ="每页显示数量" )
                                     @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
                                                                   @ApiParam(value = "当前页码")
                                     @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum) {
        PageResponse<NursingLevelVo> pageResponse = nursingLevelService.listByPage(name,status,pageSize,pageNum);

        return ResponseResult.success(pageResponse);
    }
    //根据ID查询
    @GetMapping("/{id}")
    @ApiOperation(value = "根据ID查询")
    public ResponseResult getById(@ApiParam(value = "护理等级ID")
            @PathVariable("id") Long id){
           NursingLevel nursingLevel = nursingLevelService.getById(id);
           return ResponseResult.success(nursingLevel);
    }
    //修改护理等级
    @PutMapping("/update")
    @ApiOperation(value ="修改护理等级")
    public ResponseResult upDate(@RequestBody NursingLevel nursingLevel){
         nursingLevelService.upDate(nursingLevel);
         return ResponseResult.success();
    }
    //删除护理等级
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除护理等级")
    public ResponseResult delete(@ApiParam(value = "护理等级ID") @PathVariable Long id){
          nursingLevelService.delete(id);
        return ResponseResult.success();
    }
    //启用禁用
    @ApiOperation(value = "启用禁用")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult onOff(@PathVariable @ApiParam(value = "护理等级ID") Long id,
                                @PathVariable @ApiParam(value = "状态，0：禁用，1：启用") Integer status){
        nursingLevelService.onOff(id,status);
        return ResponseResult.success();
    }


}
